
document.write("<script type='text/javascript' src='js/jquery-2.0.0.js'></script>");
document.write("<script type='text/javascript'  src='layer/layer.js'></script>");
document.write("<script type='text/javascript' src='layer/extend/layer.ext.js'></script>");
$(document).ready(function(){
	$("#renyuan2").click(function(){
		//location.href ='Customer.jsp';
		
		$(".kuang3").html("<div class='d1'></div><div class='tou1'></div><div class='tou2'></div><div class='tou3'></div>" );
	    $(".d1").append("<p class='font'>当前位置：人员管理</p>");
	    $(".tou3").html("<h style='color:#3786c7;font-weight:blod; font-size:16px'>总共有<h id='number'></h>条数据,每页显示5条数据</h>&nbsp;<input type='button' value='上一页'   onClick='projectshangyiye2()' class='jihuabutton'>&nbsp<h id='page'>1</h>&nbsp<input type='button' value='下一页' onClick='projectxiayiye2()'  class='jihuabutton'>");
	    $(".tou1").append("<div class='tianjiajihua' id='zengjia'>添加人员</div><input class='sousuo' type='text'><div class='sousuobutton'>搜索</div>");	 
	    //$("#xiangmu1").show();
		 $("#zengjia").click(function(){
			 layer.open({
					type:1,
					skin:'layui-layer-demo',
					area:['1000px','200px'],
					shadeClose:true,
					content:'<form id="zengjia1111" method="post">'
						+'<center ><table><tr>'
						+'		<th style="width: 20px; height:35px;">员工姓名</th>'
						+'		<th style="width: 20px; height:35px;">员工类型</th>'
				        +'		<th style="width: 20px; height:35px;">员工工号</th>'
				        +'		<th style="width: 20px; height:35px;">联系方式</th>'
				        +'		<th style="width: 20px; height:35px;">创建时间</th></tr>'
				        +'	<tr>'
				        +'      <td><input type="text" name="userName"  /></td>'
				        +'      <td><input type="text" name="userRole" /></td>'
				        +'      <td><input type="text" name="jobNumber"  /></td>'
				        +'      <td><input type="text" name="phoneNumber"  /></td>'
				        +'      <td><input type="text" name="createTime" readonly /></td></tr></table>'
				        +'<br><input type="button"  onClick="userzj_xm()"  value="确认"  id="anniu" name="确认" $nbsp,$nbsp/></center>'
				        +'</form>'
			 });
		 });
	    project2();
	    projectpage2();
});
	});
function project2(){
	projectpage2();
	$("#page").html("1");
	projectselect2();
}
function projectpage2(){
	 $.ajax({
     	type:'post',
			data:'',
			async:false,
			url:"userpage.do",
			dataType:'json',
			success:function(data){
				$("#number").html(data.num);
				
			}
			});
}
function projectshangyiye2(){
	var page=$("#page").html();
	if(page==1){
		alert("已经是第一页了");
	}
	else{
		page=page-1;
		$("#page").html(page);
		projectselect2();
	}
}
function projectxiayiye2(){
	var page=$("#page").html();
	var number=$("#number").html();
//	alert($("#number").html());
	var zong= parseInt(number/5);
//	alert(zong);
    if(!(number%5)){
    	
	}else{
	zong++;
	}
	if(page==zong||number==0){
		alert("已经是最后一页了");
	}
	else{
		page++;
		$("#page").html(page);
		projectselect2();
	}
}
function projectselect2(){
		$.ajax({
			type:'post',
			data:{"userId":$("#page").html()},
			dataType:'json',
			url:"renyuan2.do",
			success:function(data){
				if(data.length==0){
					$(".tou2").html("暂无记录");
				}
				else{$(".tou2").html("");
				$(".tou2").append("<table class='hovertable' style='width:840px'>");
				
				$(".tou2").append("<tr>"
				        +"      <th scope='col' style='width: 250px; '><center>员工姓名</center></th>"
				        +"		<th scope='col' style='width: 250px; '><center>员工类型</center></th>"
				        +"		<th scope='col' style='width: 100px; '><center>员工工号</center></th>"
				        +"		<th scope='col' style='width: 100px; '><center>联系方式</center></th>"
				        +"		<th scope='col' style='width: 250px; '><center>创建时间</center></th>"
				        +"		<th scope='col' style='width: 100px; '><center>修改</center></th>"
				        +"		<th scope='col' style='width: 100px; '><center>删除</center></th>"
				        +"   </tr>");
				 for(var i=0;i<data.length;i++){ 
					 $(".tou2").append("<tr>"
						        +"       <td class='row' id='role'><center>"+data[i].userName+"</center></td>"
						        +"        <td class='row' id='name'><center>"+data[i].userRole+"</center></td>"
						        +"        <td class='row' id='number1'><center>"+data[i].jobNumber+"</center></td>"
						        +"        <td class='row' id='phone'><center>"+data[i].phoneNumber+"</center></td>"
						        +"        <td class='row' id='time'><center>"+data[i].createTime+"</center></td>"
						        +"       <td class='row' id='"+i+"' name='xiugai'><center><img src='images/mod.gif'></center></td>"
						        +"        <td class='row' id='"+i+"' name='shanchu'><center><img src='images/del.gif'></center></td>"
						        +"    </tr>");
						 }
				 $(".tou2").append("</table>");
				 
				 $(".tou2").append("<div style='height:15px'></div>");
				 $("td[name='shanchu']").click(function(){
					 var id=this.id;
					 layer.open({
						 type:1,
						 skin:'layui-layer-demo',
						 area:['1000px','200px'],
						 shadeClose:true,
							content:'<form id="shanchu1111" method="post">'
								+'<center><table><tr>'
								+'		<th style="width: 20px; height:35px;"><center>员工类型</center></th>'
								+'		<th style="width: 20px; height:35px;">员工姓名</th>'
								+'		<th style="width: 20px; height:35px;">员工工号</th>'
						        +'		<th style="width: 20px; height:35px;">联系方式</th>'
						        +'		<th style="width: 20px; height:35px;">创建时间</th></tr>'
						        +'	<tr>'
						        +"<input type='hidden'; style='border:0px' name='user1Id' value='"+data[id].userId+"' >" 
						        +'      <td><input type="text" name="userRole" value="'+data[id].userRole+'"/ readonly></td>'
						        +'      <td><input type="text" name="userName" value="'+data[id].userName+'" readonly/></td>'
						        +'      <td><input type="text" name="jobNumber" value="'+data[id].jobNumber+'" readonly/></td>'
						        +'      <td><input type="text" name="phoneNumber" value="'+data[id].phoneNumber+'" readonly/></td>'
						        +'      <td><input type="text" name="createTime" value="'+data[id].createTime+'" readonly/></td></tr></table>'
						        +'<br><input type="button" value="确认" onClick="usersc_xm()" id="anniu" name="确认" $nbsp,$nbsp/></center>'
						        +'</form>'
					 });
				 });
				 
				 $("td[name='xiugai']").click(function(){
					 var id = this.id;
						layer.open({
							type:1,
							skin:'layui-layer-demo',
							area:['1000px','200px'],
							shadeClose:true,
							content:'<form id="xiugai1111" method="post">'
								+'<center><table><tr>'
								+'		<th style="width: 20px; height:25px;">员工姓名</th>'
								+'		<th style="width: 20px; height:25px;">员工类型</th>'
								+'		<th style="width: 20px; height:25px;">员工工号</th>'
						        +'		<th style="width: 20px; height:25px;">联系方式</th>'
						        +'	<tr>'
						        +'<input type="hidden"; style="border:0px" name="user1Id" value="'+data[id].userId+'">' 
						        +'      <td><input type="text" name="userName" value="'+data[id].userName+'"/ ></td>'
						        +'      <td><input type="text" name="userRole" value="'+data[id].userRole+'"/ readonly></td>'
						        +'      <td><input type="text" name="jobNumber" value="'+data[id].jobNumber+'"/></td>'
						        +'      <td><input type="text" name="phoneNumber" value="'+data[id].phoneNumber+'"/></td></tr></table>'
						        +'<br><input type="button" value="确认" onClick="userxg_xm()" id="anniu" /></center>'
						        +'</form>'
							});
					});
				}
			}
				});
//		$("#version").css("background","#27a2e6");
		event.stopPropagation();	
}
function userzj_xm(){
		$.ajax({
			type:'post',
			data:$("#zengjia1111").serialize(),
			url:"user_zj.do",
			dataType:'json',
			success:function(data){
				layer.closeAll();
				projectpage2();
				projectselect2();	
			},
		});
	}
function userxg_xm(){
	$.ajax({
		type:'post',
		data:$("#xiugai1111").serialize(),
		url:"user_xg.do",
		dataType:'json',
		success:function(data){
			layer.closeAll();
			projectpage2();
			projectselect2();
		}
	});
}
function usersc_xm(){
	$.ajax({
		type:'post',
		data:$("#shanchu1111").serialize(),
		url:"user_sc.do",
		dataType:'json',
		success:function(data){
			layer.closeAll();
			projectpage2();
			projectselect2();
		}
	});
}